package com.mall.service.marketing.controller;

import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.SmsFlashPromotion;
import com.mall.service.marketing.service.FlashService;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @ClassName FlashController
 * @Description 商城活动控制器
 * @Author Young
 * @Date 2023/3/11 23:32
 * @Version 1.0
 */
@RestController
@RequestMapping("/flash")
public class FlashController {

    @Autowired
    private FlashService flashService;

    /**
     * 添加活动
     * @param smsFlashPromotion
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody SmsFlashPromotion smsFlashPromotion){
        flashService.create(smsFlashPromotion);//TODO 前端日期不能传 时分秒
        return CommonResult.success(null,"添加活动成功");
    }

    /**
     * 删除活动
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id){
        flashService.delete(id);
        return CommonResult.success(null,"删除成功");
    }

    /**
     *根据活动名称分页查询
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(String  keyword,Integer pageNum, Integer pageSize){
        CommonPage page = flashService.list(keyword,pageNum,pageSize);
        return CommonResult.success(page,"查询成功");
    }

    /**
     * 修改上下线状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/update/status/{id}")
    public CommonResult updateStatus(@PathVariable Integer id, Integer status){
        flashService.updateStatus(id,status);
        return CommonResult.success(1,"修改成功");
    }

    /**
     * 编辑活动
     * @param id
     * @param smsFlashPromotion
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Integer id, @RequestBody SmsFlashPromotion smsFlashPromotion){
        flashService.update(id,smsFlashPromotion);
        return CommonResult.success(1,"修改成功");
    }

    /**
     * 获取活动详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult getFlash(@PathVariable Integer id){
        SmsFlashPromotion smsFlashPromotion = flashService.getFlash(Long.valueOf(id));
        return CommonResult.success(smsFlashPromotion,"获取成功");
    }
}
